<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/font-awesome.min.css" />
    <link rel="stylesheet" type="text/css" id="yejiancss" />
    <style type="text/css">
    </style>
</head>
<body>
    <header class="aui-bar aui-bar-nav" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="back()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title"></div>
        <a class="aui-pull-right aui-btn" tapmode onclick="opensearch()">
            <span class="aui-iconfont aui-icon-search"></span>
        </a>
    </header>
    <div id="main">
        <ul class="aui-list aui-media-list aui-list-noborder" id="indexlist"></ul>
        <div id="loading" class="aui-hide aui-text-center"><span class="fa-2x fa fa-spinner fa-spin"></span></div>
    </div>
    <script id="indexlist-temp" type="text/x-dot-template">
      {{? it.databook}}
        {{ for(var i=0,len=it.databook.length;i<len;i++) { }}
          {{? it.databook[i].book_name}}
            <li class="aui-list-item aui-margin-b-10" tapmode onclick="openbook({{=it.databook[i].book_id}})">
              <div class="aui-media-list-item-inner">
                <div class="aui-list-item-media">
                    <img src="{{? it.databook[i].image}}{{=indexSetting.url}}../data/attachment/forum/{{=it.databook[i].image}}{{??}}../image/book.png{{?}}">
                </div>
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-text">
                        <div class="aui-list-item-title">{{=it.databook[i].book_name}}</div>
                    </div>
                    <div class="aui-list-item-text aui-ellipsis-2">
                        {{=it.databook[i].desco||'这本书暂无简介'}}
                    </div>
                    <div class="aui-info aui-margin-t-10" style="padding:0">
                        <div class="aui-info-item">
                            <img src="{{=it.databook[i].avatar}}" style="width:1rem" class="aui-img-round" /><span class="aui-margin-l-5">{{=it.databook[i].author}}</span>
                        </div>
                        <div class="aui-info-item">
                            <span class="aui-label  aui-label-warning aui-label-outlined ">{{=it.databook[i].category_name}}</span>
                        </div>
                    </div>
                </div>
              </div>
            </li>
            {{?}}
          {{ } }}
        {{??}}
          <li class="aui-list-header">
             当前无排行数据
          </li>
        {{?}}
    </script>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/dot.js"></script>
<script type="text/javascript" src="../script/aui-toast.js"></script>
<script type="text/javascript">
var toast = new auiToast({});
toast.loading({
    title:"loading...",
    duration:2000
})
var indexSetting = $api.getStorage('appinfo');
indexSetting.userinfo = $api.getStorage('userinfo');
indexSetting.loading = false;
indexSetting.current = 1;
indexSetting.total = 2;
apiready = function() {
    autocheckyejian();
    $api.fixStatusBar($api.dom('header'));
    api.parseTapmode();
    api.addEventListener({
        name: 'keyback'
    }, function(ret, err) {
        if (ret) {
            back();
        }
    });
    indexSetting.paihangid = api.pageParam.paihangid;
    if (api.pageParam.name == 'yuedu') {
        indexSetting.name = '阅读榜';

    } else if (api.pageParam.name == 'haoping') {
        indexSetting.name = '好评榜';

    } else if (api.pageParam.name === 'jingxuan') {
        indexSetting.name = '精选榜';

    } else if (api.pageParam.name == 'shoucang') {
        indexSetting.name = '收藏榜';

    }
    $api.text($api.byId('title'), indexSetting.name);
    initload();
    api.addEventListener({
        name: 'scrolltobottom',
        extra: {
            threshold: 20
        }
    }, function(ret, err) {
        if (!indexSetting.loading) {
            indexSetting.loading = true;
            $api.removeCls($api.byId('loading'), 'aui-hide');
            if (indexSetting.total >= indexSetting.current) {
                initload();
            } else {
                $api.html($api.byId('loading'), '没有了');
            }
            indexSetting.loading = false;
        }
    });
}

//  初始化
function initload() {
    api.ajax({
        url: indexSetting.url + 'api.php?appkey=' + indexSetting.appkey + '&type=get&module=paihanginfo&param=current----' + indexSetting.current + ',paihangid----' + indexSetting.paihangid,
        method: 'get'
    }, function(ret, err) {
        if (ret) {
            if (ret.status) {
                indexSetting.current += 1;
                indexSetting.total = ret.total;
                var temp = $api.text($api.byId("indexlist-temp"));
                var dottemp = doT.template(temp);
                var html = dottemp(ret);
                $api.append($api.byId('indexlist'), html);
            } else {
                $api.html($api.byId('loading'), '没有了');
                $api.removeCls($api.byId('loading'), 'aui-hide');
            }
            toast.hide();
        } else {
            toast.fail({
                title: err.msg,
                duration: 2000
            });
        }
    });
}
</script>
</html>